import { listCatalogType } from '@/api/tree'

export default {
  namespaced: true,
  state: {
    treeType: {}, // 目录树类型
    treeTypeId: {} // 目录树类型
  },
  mutations: {
    freshTreeType: (state, treeType) => {
      state.treeType = treeType
    },
    freshTreeTypeId: (state, treeTypeId) => {
      state.treeTypeId = treeTypeId
    }
  },
  actions: {
    getListCatalogType({ commit }) {
      listCatalogType().then((res) => {
        if (res.data) {
          const treeType = {}
          const treeTypeId = {}
          res.data.forEach((item) => {
            treeType[item.name] = item.id
            treeTypeId[item.id] = item.name
          })
          commit('freshTreeType', treeType)
          commit('freshTreeTypeId', treeTypeId)
        }
      })
    }
  }
}
